package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.UserOwner;
import com.yh.homestay.service.UserOwnerService;
import com.yh.homestay.common.QiNiuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserOwnerController
 * @Description 房东Controller
 * @Date 2020/1/13 17:25
 */
@RestController
@Api(description = "房东管理")
@RequestMapping(value = "/owner")
public class UserOwnerController {

    @Autowired
    private UserOwnerService ownerService;

    /**
     * @param ownerName
     * @param page
     * @param limit
     * @Date: 2020/1/14 17:52
     * @Description: 获取房东列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "房东信息列表", module = "房东管理")
    @ApiOperation(value = "获取房东列表", notes = "获取房东信息列表或者模糊查询数据")
    public HomeStayResult selectAll(String ownerName, Integer page, Integer limit) {
        return ownerService.showUserOwner(ownerName, page, limit);
    }

    /**
     * @param userOwner
     * @Date: 2020/1/14 17:52
     * @Description: 添加房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SystemLog(methods = "添加房东", module = "房东管理")
    @ApiOperation(value = "添加房东", notes = "添加房东信息")
    public HomeStayResult addOwner(UserOwner userOwner) {
        userOwner.setOwnerPhoto(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerPhoto());
        userOwner.setOwnerIdcardA(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerIdcardA());
        userOwner.setOwnerIdcardB(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerIdcardB());
        return ownerService.insertUserOwner(userOwner);
    }

    /**
     * @param id
     * @Date: 2020/1/14 17:52
     * @Description: 回显房东信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/one/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "回显房东信息", notes = "根据id回显房东信息")
    public HomeStayResult editOwner(@PathVariable("id") Integer id) {
        return ownerService.selectOneUserOwner(id);
    }

    /**
     * @param userOwner
     * @Date: 2020/1/14 17:52
     * @Description: 修改房东信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SystemLog(methods = "修改房东信息", module = "房东管理")
    @ApiOperation(value = "修改房东信息", notes = "修改房东信息")
    public HomeStayResult editMember(UserOwner userOwner) {
        return ownerService.updateUserOwner(userOwner);
    }

    /**
     * @param ownerId
     * @Date: 2020/1/14 17:52
     * @Description: 删除房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @SystemLog(methods = "删除房东", module = "房东管理")
    @ApiOperation(value = "删除房东", notes = "根据删除房东")
    public HomeStayResult deleteById(Integer ownerId) {
        return ownerService.deleteUserOwner(ownerId);
    }

    /**
     * @param ids
     * @Date: 2020/1/14 17:52
     * @Description: 批量删除房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个房东", module = "房东管理")
    @ApiOperation(value = "批量删除房东", notes = "根据ids批量删除房东")
    public HomeStayResult delectAll(@RequestParam List<Integer> ids) {
        return ownerService.deleteBatchUserOwner(ids);
    }
}
